package com.xb.p15_intentdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.KeyEventDispatcher;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void btnClick(View view){
        //Toast.makeText(this,"btnClick_explicit...",Toast.LENGTH_SHORT).show();

        if(view.getId()==R.id.btn_explicit){
            //显式跳转-->A
            Intent intent =new Intent();
            ComponentName componentName= new ComponentName(this,A_Activity.class);
            intent.setComponent(componentName);
            startActivity(intent);
        }
        if(view.getId()==R.id.btn_hidden){
           //隐式调用
            Intent intent =new Intent();
            //在Manifests中配置相关的动作,通过意图过滤器来配置允许通过的动作
            intent.setAction("btn_hidden");
            startActivity(intent);
        }
        if(view.getId()==R.id.btn_data_01){
            //data 打开网页
            Intent intent =new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://www.baidu.com"));
            startActivity(intent);
        }
        if(view.getId()==R.id.btn_data_02){
            //data 打开通信录
            Intent intent =new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("content://com.android.contacts/contacts"));
            startActivity(intent);
        }
        if(view.getId()==R.id.btn_data_03){
            //data 打开通信录
            Intent intent =new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("content://com.android.contacts/contacts/1"));
            startActivity(intent);
        }
    }
}